package cn.dckeji.gameBox.controller;


import cn.dckeji.gameBox.common.utils.MD5;
import cn.dckeji.gameBox.common.utils.ResultUtil;
import cn.dckeji.gameBox.dto.Result;
import cn.dckeji.gameBox.entity.Banner;
import cn.dckeji.gameBox.entity.Banner;
import cn.dckeji.gameBox.service.BannerService;
import com.baomidou.mybatisplus.plugins.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.Date;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Lucas
 * @since 2018-08-20
 */
@RestController
@RequestMapping("/banner")
public class BannerController {
    @Autowired
    private BannerService bannerService;
    @GetMapping("getBannerList")
    public Map<String, Object> getBannerList(Integer page, Integer limit, @RequestParam(value = "realName",required = false) String realName, @RequestParam(value = "loginName",required = false) String loginName, @RequestParam(value = "date",required = false) String date){
        Page<Banner> bannerPage = new Page<>();
        bannerPage.setSize(limit);
        bannerPage.setCurrent(page);
        bannerPage = bannerService.selectPage(bannerPage,null);
        return ResultUtil.resultPage(bannerPage.getTotal(),bannerPage.getRecords());
    }

    /**
     * 保存角色
     * @param banner
     * @return
     */
    @PostMapping("saveBanner")
    public Result saveBanner(Banner banner) {
        if (banner.getId() == null) {
             bannerService.insert(banner);
        }else {
            bannerService.updateById(banner);
        }
        return ResultUtil.success();
    }
    /**
     * 删除广告图
     * @param id
     * @return
     */
    @PostMapping("deleteById")
    public Result deleteById(Integer id) {
        bannerService.deleteById(id);
        return ResultUtil.success();
    }

}

